-
Notifications
You must be signed in to change notification settings - Fork 1.1k
abc: add ABC base class #1003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
abc: add ABC base class #1003
Conversation
This trivial addition will allow less code differences between standard python classes and micropython code. Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Was about to create an pull request for exactly the same change. Would really like to see this merged into the master branch. |
Ping, anyone? |
It...doesn't really add much! :P If there were more of an implementation it would be more compelling. Can you give an example of code that was easier to port with this? |
From the python docs (https://docs.python.org/3/library/abc.html#abc.abstractmethod), the
My personal use case is at https://github.com/rasjidw/sparrowrpc-python/blob/main/src/sparrowrpc/bases.py where I define a number of base classes using both the The is no problems with the classes and decorators being no-op classes / functions in micropython since in cpython it is really just there for developer erganomics and doesn't actually affect the runtime operation in any way. On reflection, it is probably worth adding in the other classes and functions from the abc module as dummy entries too. |
Apart from using a metaclass and slots (neither of which MicroPython supports) this is actually the same as CPython which has: class ABC(metaclass=ABCMeta):
"""Helper class that provides a standard way to create an ABC using
inheritance.
"""
__slots__ = () So I think this is a good addition. As mentioned above, it allows doing |
Just to clarify - it is not so necessary for code that you are porting to micropython, but very useful if you want to have a single codebase that works both with cpython and micropython. |
Actually, this is not completely true, as the cpython ABC class has a method to
So in fact probably better to limit this to the dummy |
this trivial addition will allow less code differences between standard python classes and micropython code.